﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Utility;
using System.Data;
using Runda.EShop.Bll;

namespace Runda.EShop.SaaS.UserControl
{
    public partial class MessageTips : UserControlBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //未读消息提醒
                List<SqlDbParameter> parms = new List<SqlDbParameter>();
                SqlDbParameter parm = null;

                parm = new SqlDbParameter();
                parm.ColumnName = "[ObjectType]";
                parm.ColumnType = DbType.Int32;
                parm.ParameterName = "@ObjectType";
                parm.ParameterValue = (int)EnumHelper.UserType.Administrator;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);

                parm = new SqlDbParameter();
                parm.ColumnName = "[ObjectID]";
                parm.ColumnType = DbType.Guid;
                parm.ParameterName = "@ObjectID";
                parm.ParameterValue = base.Page.User.Identity.LoginUser.UserID;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);

                parm = new SqlDbParameter();
                parm.ColumnName = "[IsRead]";
                parm.ColumnType = DbType.Int32;
                parm.ParameterName = "@IsRead";
                parm.ParameterValue = 0;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);

                int RecordCount = 0;
                SysMessageBll bll = new SysMessageBll();
                RecordCount = bll.Count(parms);

                if (RecordCount > 0)
                {
                    string Url = ResolveUrl("~/MessageManage/MessageList.aspx");
                    base.Page.ClientScript.RegisterStartupScript(this.GetType(), "sdf", "<script>$.ligerDialog.tip({ title: '提示信息', content: '您有<a href=\"" + Url + "\" style=\"color:red;\">" + RecordCount + "</a>条新消息！' });</script>");

                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);
        }
    }
}